package jlxy.ise.cloudcourse.service;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 *
 * @author yecq
 */
@Service
public class SampleService {

    @Autowired
    private JdbcTemplate jdbc;

    public List<Map<String, Object>> listUsers() {
        return this.jdbc.queryForList("select * from user");
    }

    public Map<String, Object> getUser(String name) {
        return this.jdbc.queryForMap("select name,passwd,cellphone,id,username1 from user where name = ?", name);
    }

    public void addUser(String name, int age) {
        this.jdbc.update("insert into user(name,age) values(?,?)", name, age);
    }

    public void modifyUser(String id, String name, int age) {
        this.jdbc.update("update user set name=?,age=? where id=?", name, age, id);
    }

    public void removeUser(String id) {
        this.jdbc.update("delete from user where id =?", id);
    }
}
